﻿using System.ComponentModel.Design;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using ControlLibrary;

namespace ControlLibrary.ComponentModel {
    [ComplexBindingProperties("DataSource", "DisplayMember")]
    [DefaultBindingProperty("DisplayMember")]
    internal class LookupFieldActionList : ActionListBase {
        #region Properties

        private readonly LookupField linkedControl;

        [TypeConverter("System.Windows.Forms.Design.AdvancedBindingTypeConverter")]
        [Editor("System.Windows.Forms.Design.DataSourceListEditor", typeof(UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public object DataSource {
            get { return GetPropertyByName("DataSource").GetValue(linkedControl); }
            set { GetPropertyByName("DataSource").SetValue(linkedControl, value); }
        }

        [TypeConverter("System.Windows.Forms.Design.AdvancedBindingTypeConverter")]
        [Editor("System.Windows.Forms.Design.DataSourceListEditor", typeof(UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public object LookupSource {
            get { return GetPropertyByName("LookupSource").GetValue(linkedControl); }
            set { GetPropertyByName("LookupSource").SetValue(linkedControl, value); }
        }

        [Editor(typeof(QueryEditor), typeof(UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public object FormQueryType {
            get { return GetPropertyByName("FormQueryType").GetValue(linkedControl); }
            set { GetPropertyByName("FormQueryType").SetValue(linkedControl, value); }
        }


        [Editor(typeof(CrudEditor), typeof(UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public object FormCrudType {
            get { return GetPropertyByName("FormCrudType").GetValue(linkedControl); }
            set { GetPropertyByName("FormCrudType").SetValue(linkedControl, value); }
        }

        #endregion

        public LookupFieldActionList(LookupField component, ControlDesigner designer)
            : base(component, designer) {
                linkedControl = (LookupField)LinkedControl; 
        }

        public override DesignerActionItemCollection GetSortedActionItems() {
            var items = new DesignerActionItemCollection();

            items.Add(new DesignerActionHeaderItem("Lookup"));
            items.Add(new DesignerActionHeaderItem("Data"));

            items.Add(new DesignerActionPropertyItem(
                "LookupSource", "Lookup Source", "Lookup", "Choose a Lookup Member."));

            items.Add(new DesignerActionPropertyItem(
                "DataSource", "Data Source", "Data", "Choose a Data Source."));

            items.Add(new DesignerActionPropertyItem(
                "FormQueryType", "Query Type", "Data", "Choose a UtfprFormQuery Type."));

            items.Add(new DesignerActionPropertyItem(
                "FormCrudType", "CRUD Type", "Data", "Choose a UtfprFormCrud Type."));

            return items;
        }
    }
}
